<?php
/**
 * admin service file Created by PhpStorm.
 * User: yang
 * Date: 2020/06/15
 */
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Service\Admin\ForumService;

class ForumController extends Controller
{
    /**
     * 视图层
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return view('Admin.forum.index');
    }
    
    /**
     * 获取列表数据
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function list(Request $request)
    {
        $get_data = $request->all();
    
        $result = ForumService::getList($get_data);
    
        return response()->json($result);
    }
    
    /**
     * 添加视图
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create()
    {
        return view('Admin.forum.create');
    }

    /**
     * 添加操作
     *
     * @param Request $request
     * @return array
     */
    public function insert(Request $request)
    {
        $post_data = $request->except(['_token']);

        return ForumService::insert($post_data);
    }

    /**
     * 编辑视图
     *
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function edit(Request $request)
    {
        $id = $request->get('id', 0);
    
        $result = ForumService::edit((int)$id);

        return view('Admin.forum.edit', $result);
    }
    
    /**
     * 编辑操作
     *
     * @param Request $request
     * @return array
     */
    public function update(Request $request)
    {
        $post_data = $request->except(['_token']);
    
        return ForumService::update($post_data);
    }
    
    /**
     * 删除操作
     *
     * @param Request $request
     * @return mixed
     */
    public function delete(Request $request)
    {
        $id = $request->get('id', 0);
    
        return ForumService::delete((int)$id);
    }
    
    /**修改状态
     *
     * @param Request $request
     * @return array
     */
    public function status(Request $request)
    {
        $post_data = $request->only(['id', 'status']);

        return ForumService::editStatus($post_data);
    }
}